#include "cximgframe.h"
#include "ui_cximgframe.h"
#include <QLCDNumber>
#include <iostream>
using namespace std;
CxImgFrame::CxImgFrame(QWidget *parent) :
    QFrame(parent),
    ui(new Ui::CxImgFrame),
    m_isShow(true)

{
    ui->setupUi(this);
    connect(this,SIGNAL(sig_showImage(const cv::Mat&)),this,SLOT(slot_showImage(const cv::Mat&)),Qt::QueuedConnection);
    connect(this,SIGNAL(sig_showCarcount(int,int)),this,SLOT(slot_showCarcount(int,int)),Qt::QueuedConnection);
    connect(this,SIGNAL(sig_break()),this,SLOT(slot_break()),Qt::QueuedConnection);

}

CxImgFrame::~CxImgFrame()
{
    delete ui;
}

void    CxImgFrame::SetLableText(const QString str)
{
    ui->label->setText(str);
}

void    CxImgFrame::GetCarCount(int &in, int &out)
{
    in=ui->lcdNumber->intValue();
    out=ui->lcdNumber_2->intValue();
}


void            CxImgFrame::slot_showImage(const cv::Mat &temp)
{
    if(m_isShow)
    {
          cv::Mat img;
          cv::cvtColor(temp,img,::CV_BGR2RGB);
          QImage qimg(img.data,img.cols,img.rows,img.step,QImage::Format_RGB888);

          qimg.scaled(ui->imgview->width(),ui->imgview->height(),Qt::KeepAspectRatio);

          ui->imgview->setPixmap(QPixmap::fromImage(qimg));
          ui->imgview->update();
    }
}


 void            CxImgFrame::slot_showCarcount(int in   ,int  out)
 {
     ui->lcdNumber->display(in);
     ui->lcdNumber_2->display(out);
 }


void CxImgFrame::on_pushButton_3_clicked(bool checked)
{
    m_isShow=checked;
    if(!checked)
    {
        ui->imgview->clear();
        ui->imgview->update();
        ui->pushButton_3->setText("打开显示");
    }
    else
    {
        ui->pushButton_3->setText("关闭显示");
    }
}
void    CxImgFrame::slot_break()
{
    m_isShow=false;

}
